<?php

include("header.php");
$restoid=null;
if(isset($_GET["nationid"])&isset($_GET["typeid"])){
	$nationid=$_GET["nationid"];
	$typeid=$_GET["typeid"];
}else{
	redirect("index.php");
}
?>
<?php

	// Connect to server and select databse.
	// Connect to server and select databse.
	$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
	$db->connect();

	if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
	if (isset($_GET["sort"])) { $order_col  = $_GET["sort"]; } else { $order_col='RESTO_NAME_$_lang'; };

	if ($page<0 || ((int)$page != $page)) {
		$message  = 'Invalid page number: ' .$page . "\n";
		die($message);
	}

	$start_from = ($page-1) * 15;
	$nationsql="SELECT nation_name.NATION_NAME_$_lang AS nation FROM nation_name WHERE nation_name.NATION_ID =$nationid";
	$typesql="SELECT type_resto.TYPE_NAME_$_lang AS type FROM type_resto WHERE type_resto.TYPE_ID=$typeid";
	$sql = "SELECT info_resto.RESTO_ID AS restoid, info_resto.RESTO_NAME_$_lang AS restoname,
	info_resto.INTRO_PIC AS pic, info_resto.RESTO_INTRO_$_lang AS resto_intro,
	info_resto.RESTO_ADDR AS resto_addr,HAS_COUPON,HAS_RESERV FROM info_resto
	WHERE info_resto.RESTO_TYPE_ID =$typeid AND info_resto.RESTO_NATION =$nationid";
	$rs_result = mysql_query ($sql);
	$nation = $db->query_first ($nationsql);
	$type = $db->query_first($typesql);

	$rs_count_result = $db->query_first ("SELECT COUNT(RESTO_ID) as total FROM info_resto WHERE info_resto.RESTO_TYPE_ID =$typeid AND info_resto.RESTO_NATION =$nationid");
	$total_records = $rs_count_result['total'];
	$total_pages = ceil($total_records / 15);
	// Check result
	// This shows the actual query sent to MySQL, and the error. Useful for debugging.
	if (!$rs_result) {
		$message  = 'Invalid query: ' . mysql_error() . "\n";
		$message .= 'Whole query: ' . $sql;
		die($message);
	}
	$db->close();
	?>
<div class="contactBg">
 <div class="contactDeit fl">
  <div class="contact noLine">
    <ul>
    <?php if($_lang==FR){?>
      <li><?php if($_lang==FR){ echo "Accueil";} else if($_lang==ARB){echo "الصفحة الرئيسية";}?>></li>
      <li><?php echo $nation['nation']; ?>></li>
      <li><?php echo $type['type']; ?></li>
      <?php }else{?>
       <li><?php echo $type['type']; ?></li>
       <li><<?php echo $nation['nation']; ?></li>
       <li><<?php if($_lang==FR){ echo "Accueil";} else if($_lang==ARB){echo "الصفحة الرئيسية";}?></li>
      <?php }?>
    </ul>
  </div>
  <!--contact end of-->
  <form id="mainform" action="">
	<?php
		while ($row = mysql_fetch_assoc($rs_result)) {
		    
				$infor = strip_tags($row['resto_intro']);
			
	?>
	  <div class="searchList">
		<p class="fl"><a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $nationid;?>&typeid=<?php echo $typeid;?>">
			<img src=<?php echo $row['pic']; ?> width="250" height="112" alt="" /></a></p>
		<dl class="fl">
		  <dt><a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $nationid;?>&typeid=<?php echo $typeid;?>" style="color:#000"><?php echo $row['restoname']; ?></a> </dt>
		  <dd class="searchDd"><?php echo $row['resto_addr']; ?></dd>
		  <?php if($_lang==FR){?>
			  <dd><?php echo cut_str($infor,220); ?>...
			  <a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $nationid;?>&typeid=<?php echo $typeid;?>" class="red">Suite</a></dd>
		  <?php }else{?>
			  <table>
			  <tr>
			  <td>
			  <dd><div style="direction: rtl;"><?php echo cut_str($infor,220); ?>...</div></dd>
			  </td>
			  </tr>
			  <tr>
			  <td>
			  <dd><a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $nationid;?>&typeid=<?php echo $typeid;?>" class="red">Suite</a></dd>
			  </td>
			  </tr>
			  </table>
		  <?php }?>
		</dl>
		<?php if(ord($row['HAS_RESERV'])){?>
		<a href="reserver.php?restoid=<?php echo $row['restoid']; ?>" class="reserver top30"></a>
		<?php }else if($_lang==FR){?>
		<img src="/images/reserver2.png" style="position: absolute; right:24px;top:30px">
		<?php }else{?>
		<img src="/images/reserver2-arabe.png" style="position: absolute; right:24px;top:30px">
		<?php }?>
		<?php if(ord($row['HAS_COUPON'])){?>
		<a href="coupon.php?restoid=<?php echo $row['restoid']; ?>" class="coupon top80"></a>
		<?php }else if($_lang==FR){?>
		<img src="/images/coupon2.png" style="position: absolute; right:24px;top:80px">
		<?php }else{?>
		<img src="/images/coupon2-arabe.png" style="position: absolute; right:24px;top:80px">
		<?php }?>
	  </div>
	<?php
	};
	?>
  </form>
  <!--searchList end of-->
  </div>
</div>
<!--contactBg end of-->
<?php
include("foot.php");
?>

